﻿using System;
using System.Collections.Generic;
using System.Text;
using RobotRace.utils.graph;
using RobotRace.Geometry;

namespace RobotRace.engine.path
{
    public class SinglePathCreator : PathCreationStrategy
    {
        public PathGraph createPathGraph(List<Point2D> originalCheckpoints)
        {
            PathGraph pathGraph = new PathGraph();
            if (originalCheckpoints.Count == 0)
            {
                return pathGraph;
            }
            Node previousNode = null;
            int counter = 0;
            foreach (Point2D point in originalCheckpoints)
            {
                Node node = new Node(point);
                node.nodeNumberOnPath = counter++;
                if (previousNode != null)
                {
                    previousNode.addEdgeTo(node, 1);
                }
                previousNode = node;
                pathGraph.addNode(node);
            }
            Node firstNode = pathGraph.getFirstNodeInSequence();
            previousNode.addEdgeTo(firstNode, 1);
            return pathGraph;
        }
    }
}
